/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-08-20 08:58:18
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2024-08-20 09:26:19
 * @FilePath: /vue3-uniapp/src/service/utils/useDebounceFn.ts
 */
import { debounceFn } from '@/utils/index';

export const useDebounceFn = <T extends (...args: any[]) => any>(
    fn: T,
    wait: number,
    immediate = false
): [(...args: Parameters<T>) => void, () => void] => {
    const [excute, clear] = debounceFn(fn, wait, immediate);

    // 组件卸载时清除定时器
    onBeforeUnmount(clear);

    return [excute, clear];
};
